﻿<%@ Page Title="Role Management" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Role.aspx.cs" Inherits="CSPTest.Admin.Role" %>

<%@ Import Namespace="System.Linq" %>

<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="../content/entity.css" rel="stylesheet" type="text/css" />

    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../js/jquery-ui.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            $("input:submit,input:button").button();

            $(".entity-delete a")
                .attr("title", "Delete")
                .bind("click", function() {
                    return confirm("Are you sure to delete this item?");
                });

            $(".entity-modify a")
                .attr("title", "Modify");

            $(".entity-belongsto").val($(".entity-belongsto").attr("u"));
        });
    </script>

</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <h1>
            Role Management (Admin Module)</h1>
        <asp:TextBox ID="SearchText" runat="server"></asp:TextBox>
        <asp:Button runat="server" ToolTip="Search by the keywords" Text="Search" />
        <asp:Button runat="server" ToolTip="Clear all the search keywords" Text="Clear" ID="BtnClear" />
        <asp:GridView ID="gvMain" runat="server" AutoGenerateColumns="False" DataKeyNames="RoleID"
            DataSourceID="edsMain" AllowPaging="True" AllowSorting="True" EmptyDataText="没有数据">
            <Columns>
                <asp:BoundField DataField="RoleID" HeaderText="RoleID" ReadOnly="True" SortExpression="RoleID" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="BelongsTo" HeaderText="BelongsTo" SortExpression="BelongsTo" />
                <asp:TemplateField HeaderText="Countries"> 
                    <ItemTemplate>
                        <asp:Repeater runat="server" DataSource='<%# from t in EvalX("Countries") as System.Collections.Generic.IEnumerable<Entity.Country> where !t.Disabled select t %>'>
                            <ItemTemplate>
                                <%#Eval("Name") %>,
                            </ItemTemplate>
                        </asp:Repeater>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Pages">
                    <ItemTemplate>
                        <asp:Repeater runat="server" DataSource='<%# FilterPages(EvalX("AspxPages"), "Admin") %>'>
                            <ItemTemplate>
                                <%#Eval("FullName") %>,
                            </ItemTemplate>
                        </asp:Repeater>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:ButtonField CommandName="Modify" ButtonType="Link" ItemStyle-CssClass="entity-modify" />
                <asp:ButtonField CommandName="Disable" ButtonType="Link" ItemStyle-CssClass="entity-delete" />
            </Columns>
        </asp:GridView>
        <asp:Button ID="BtnAdd" runat="server" Text="Add" />
        <asp:DetailsView ID="dvMain" runat="server" AutoGenerateRows="False" DataKeyNames="RoleID"
            DataSourceID="edsMain">
            <Fields>
                <asp:BoundField DataField="RoleID" HeaderText="RoleID" ReadOnly="True" SortExpression="RoleID" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                
                <%--所属模块--%>
                <asp:TemplateField>
                    <EditItemTemplate>
                        <select name="BelongsTo" class="entity-belongsto" u="<%#Eval("BelongsTo") %>">
                            <option>--请选择--</option>
                            <option value="CCS">CCS</option>
                            <option value="Admin">Admin</option>
                        </select>
                    </EditItemTemplate>
                    <HeaderTemplate>
                        BelongsTo
                    </HeaderTemplate>
                    <InsertItemTemplate>
                        <select name="BelongsTo">
                            <option>--请选择--</option>
                            <option value="CCS">CCS</option>
                            <option value="Admin">Admin</option>
                        </select>
                    </InsertItemTemplate>
                </asp:TemplateField>

                <%--国家--%>
                <asp:TemplateField HeaderText="Countries">
                    <EditItemTemplate>
                        <asp:Repeater runat="server" DataSourceID="odsCountryRole">
                            <ItemTemplate>
                                <input type="checkbox" name="CountryList" value="<%#Eval("CountryID") %>" <%#Eval("Accessable") %> /><%#Eval("Name") %><br />
                            </ItemTemplate>
                        </asp:Repeater>
                    </EditItemTemplate>
                    <HeaderTemplate>
                        Country Related
                    </HeaderTemplate>
                    <InsertItemTemplate>
                        <asp:Repeater runat="server" DataSourceID="edsCountry">
                            <ItemTemplate>
                                <input type="checkbox" name="CountryList" value="<%#Eval("CountryID") %>" /><%#Eval("Name") %><br />
                            </ItemTemplate>
                        </asp:Repeater>
                    </InsertItemTemplate>
                </asp:TemplateField>
                
                <%--页面访问--%>
                <asp:TemplateField>
                    <EditItemTemplate>
                        <asp:Repeater runat="server" DataSourceID="odsPageRole">
                            <ItemTemplate>
                                <input type="checkbox" name="PageList" value="<%#Eval("PageID") %>" <%#Eval("Accessable") %> /><%#Eval("FullName") %>
                                (<%# (CSP.BL.AccessLevel)Eval("AccessLevel")%>)<br />
                            </ItemTemplate>
                        </asp:Repeater>
                    </EditItemTemplate>
                    <HeaderTemplate>
                        Page Access
                    </HeaderTemplate>
                    <InsertItemTemplate>
                        <asp:Repeater runat="server" DataSourceID="edsPage">
                            <ItemTemplate>
                                <input type="checkbox" name="PageList" value="<%#Eval("PageID") %>" /><%#Eval("FullName") %>
                                (<%# (CSP.BL.AccessLevel)Eval("AccessLevel")%>)<br />
                            </ItemTemplate>
                        </asp:Repeater>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" ShowInsertButton="True" ButtonType="Button" />
            </Fields>
        </asp:DetailsView>
        <%--以下是数据源--%>
        <asp:EntityDataSource ID="edsMain" runat="server" ConnectionString="name=CSPEntities"
            DefaultContainerName="CSPEntities" EnableInsert="True" EnableUpdate="True" EntitySetName="Roles"
            Include="Countries, AspxPages" Where="(!it.Disabled and it.BelongsTo = N'Admin')">
        </asp:EntityDataSource>
        <asp:EntityDataSource ID="edsPage" runat="server" ConnectionString="name=CSPEntities"
            DefaultContainerName="CSPEntities" EntitySetName="AspxPages" Where="it.BelongsTo = N'Admin'">
        </asp:EntityDataSource>
        <asp:ObjectDataSource ID="odsPageRole" runat="server" SelectMethod="GetPagesWithRole"
            TypeName="CSP.BL.PageHelper">
            <SelectParameters>
                <asp:ControlParameter ControlID="gvMain" Name="roleID" PropertyName="SelectedDataKey.Value"
                    Type="Int32" />
                <asp:Parameter Name="belongsTo" DefaultValue="Admin" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:EntityDataSource ID="edsCountry" runat="server" ConnectionString="name=CSPEntities"
            DefaultContainerName="CSPEntities" EntitySetName="Countries" Where="!it.Disabled">
        </asp:EntityDataSource>
        <asp:ObjectDataSource ID="odsCountryRole" runat="server" SelectMethod="GetCountriesWithRole"
            TypeName="CSP.BL.CountryHelper">
            <SelectParameters>
                <asp:ControlParameter ControlID="gvMain" Name="roleID" PropertyName="SelectedDataKey.Value"
                    Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </div>
</asp:Content>
